﻿using System;
using System.ComponentModel.Design;
using System.Linq;
using Microsoft.VisualStudio.Shell;
using System.IO;
using System.Collections.Generic;

namespace CodeDocumentationSynchronizer.CodDocSync
{
    static class Extensions
    {

        public static void AddCommand(this OleMenuCommandService OleMenuCommandServiceInstance, int CommandId, EventHandler InvokeHandler)
        {
            OleMenuCommandServiceInstance.AddCommand(new MenuCommand(InvokeHandler, new CommandID(GuidList.guidCodDocSyncCmdSet, CommandId)));
        }

        public static OleMenuCommand AddCommand(this OleMenuCommandService OleMenuCommandServiceInstance, int CommandId, EventHandler InvokeHandler, EventHandler BeforeQueryStatusHandler)
        {
            OleMenuCommand OleMenuCommandInstance = new OleMenuCommand(InvokeHandler, null, BeforeQueryStatusHandler, new CommandID(GuidList.guidCodDocSyncCmdSet, CommandId));
            OleMenuCommandServiceInstance.AddCommand(OleMenuCommandInstance);
            return OleMenuCommandInstance;
        }

        public static System.Windows.Media.Imaging.BitmapImage ToWPFImageSource(this System.Drawing.Image Old_School_Image)
        {
            MemoryStream ms = new MemoryStream();
            Old_School_Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

            System.Windows.Media.Imaging.BitmapImage bImg = new System.Windows.Media.Imaging.BitmapImage();
            bImg.BeginInit();
            bImg.StreamSource = new MemoryStream(ms.ToArray());
            bImg.EndInit();
            ms.Dispose();

            return bImg;
        }

        public static System.Windows.Controls.Image ToWPFImage(this System.Drawing.Image Old_School_Image)
        {
            return new System.Windows.Controls.Image()
            {
                Source = Old_School_Image.ToWPFImageSource()
            };
        }
        
        public static System.Drawing.Image ToDrawingImage(this System.Windows.Controls.Image Modern_School_Image)
        {
            return System.Drawing.Image.FromStream(((System.Windows.Media.Imaging.BitmapImage)Modern_School_Image.Source).StreamSource);
        }

    }
}
